const puppeteer = require('puppeteer');
const devices = require('puppeteer/DeviceDescriptors.js');

(async () => {
  const browser = await (puppeteer.launch({
    //设置超时时间
    timeout: 15000,
    //如果是访问https页面 此属性会忽略https错误
    ignoreHTTPSErrors: true,
    // 打开开发者工具, 当此值为true时, headless总为false
    devtools: false,
    // 关闭headless模式, 不会打开浏览器
    headless: true
  }));
  const page = await browser.newPage();
  //iPhoneX模式打开百度，
  await page.emulate(devices['iPhone X'])
  await page.goto('https://www.baidu.com');
  await page.type('#index-kw', 'puppeteer')

  await page.click('#index-bn');

  await page.waitForNavigation({ timeout: 3000 })
  await page.screenshot({
    path: 'baidu.png',
    type: 'png'
  });
  browser.close();
})();
